var jQ=window.jQuery;
var joyWindow;

function jwindow_ajaxRequest(url,method,callback,datas)
{
	var cbk=callback;
	if(cbk==null||cbk=='')
	cbk=jWindow.defaultCallBack;

	   jQ.ajax({
	   url: url,
	   type:method,
	   cache:false,
	   data: datas+'&resWay=js',
	   success: cbk.success,
	   error: cbk.failure
	}); 
}


function windowConfig()
{
	this.width=700;
	this.height=400;
	this.alpha=-1;
}

var jWindow=joyWindow=({
		"windowId":"",
		"setWindowId":function(wid)
		{
			jWindow.windowId=wid;
		},
		"ajaxPostJSBack":function(url,callback,datas)
		{
			jwindow_ajaxRequest(url,"post",callback,datas+'&resWay=js&windowId='+jWindow.windowId);
		},
		"ajaxGetJSBack":function(url,callback,datas)
		{
			jwindow_ajaxRequest(url,"get",cbk,datas+'&resWay=js&windowId='+jWindow.windowId);
		},
		"initWindow":function(config)
		{
			if(config instanceof windowConfig)
			{
			 if(config.alpha>255)
				 config.alpha=255;
			 if(config.alpha>=0&&config.alpha<50)
				 config.alpha=50;
			 
			 var callback2={"success":function(text){}, "failure":function(text){alert('初始化出错，如果采用多实例方式请屏蔽初始化代码！!')}};
			 var datas="windowConfig.width="+config.width+"&windowConfig.height="+config.height+"&windowConfig.alpha="+config.alpha;
			 jwindow_ajaxRequest("initWindow_jWindow.do","get",callback2,datas);
			}
		},
		"defaultCallBack":{"success": function(text)
			 {
			 try{
			   var jsonObj=eval(text);
				 alert(jsonObj.message);
			   }catch(e)
			   {
			   alert(text);
			   }
			 },
			 "failure":function(text)
			 {
				 if(window.confirm("请求出错!  是否查看返回信息?"))
					 alert(text);
			 }}
});

